import 'package:flutter/material.dart';
import 'package:xinpin/src/ui/game/controller/game_controller.dart';
import 'package:xinpin/src/ui/game/controller/game_state.dart';
import 'package:provider/provider.dart';

class GameButtons extends StatelessWidget {
  const GameButtons({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = context.watch<GameController>();
    final state = controller.state;
    return Padding(
      padding: const EdgeInsets.all(30),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            height: 50,
            width: 140,
            decoration: BoxDecoration(
                color: Color.fromARGB(255, 210, 138, 218),
                borderRadius: BorderRadius.circular(15)),
            child: TextButton.icon(
              onPressed: controller.shuffle,
              icon: const Icon(
                Icons.replay_rounded,
                color: Color.fromARGB(255, 255, 255, 255),
              ),
              label: Text(
                state.status == GameStatus.created ? " 开始  " : " 打乱  ",
                style: const TextStyle(
                    fontSize: 18, color: Color.fromARGB(255, 255, 255, 255)),
              ),
            ),
          ),
          const SizedBox(width: 20),
          DropdownButton<int>(
            items: [3, 4, 5, 6]
                .map(
                  (e) => DropdownMenuItem(
                    child: Text("难度${e}x$e"),
                    value: e,
                  ),
                )
                .toList(),
            onChanged: (crossAxisCount) {
              if (crossAxisCount != null &&
                  crossAxisCount != state.crossAxisCount) {
                controller.changeGrid(crossAxisCount);
              }
            },
            value: state.crossAxisCount,
          ),
        ],
      ),
    );
  }
}
